package com.ysyc.driver_ee.widget;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.ysyc.driver_ee.R;

/**
 * Created by Administrator on 2017/11/17 0017.
 */

public class UploadPhotosPop {
    private PopupWindow pop;
    private Activity mActivity;
    private int[] tvID;
    private ImageView exampleIv;
    public TextView photographTv;

    public UploadPhotosPop(Activity activity) {
        this.mActivity = activity;
    }


    public void show(View v, OnPopListener onPopListener,LinearLayout ll) {
        pop = new PopupWindow(mActivity);
        View view = mActivity.getLayoutInflater().inflate(R.layout.popup_window_up_load_photos, null);
        pop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        pop.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        pop.setBackgroundDrawable(new ColorDrawable(0x80000000));
        pop.setFocusable(true);
        pop.setOutsideTouchable(true);
        pop.setContentView(view);
        pop.showAtLocation(v, Gravity.BOTTOM, 0, 0);
        photographTv = view.findViewById(R.id.tv_photograph_view);
        TextView albumTv =  view.findViewById(R.id.tv_album_view);
        TextView cancelTv = view.findViewById(R.id.tv_cancel_view);
        exampleIv = view.findViewById(R.id.iv_example_view);
        cancelTv.setOnClickListener(cancelListener);
        photographTv.setOnClickListener(v1 -> {
                    dismiss();
                    onPopListener.onPhotographItemClick(ll);
                }
        );
        albumTv.setOnClickListener(v1 -> {
            dismiss();
            onPopListener.onAlbumItemClick(ll);
        });
    }

    public void setExampleImageView(int ivRes) {
        exampleIv.setImageResource(ivRes);

    }

    private View.OnClickListener cancelListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    };

    public void dismiss() {
        if (pop != null && pop.isShowing())
            pop.dismiss();
    }


    /***
     * 按钮回调接口
     *
     * @author Sloven
     *
     */
    public interface OnPopListener {
        void onPhotographItemClick(LinearLayout ll);

        void onAlbumItemClick(LinearLayout ll);
    }


}
